package com.zj.aspects;

import com.zj.web.bean.MyUserDTO;
import com.zj.web.controller.AuthResponse;
import lombok.extern.java.Log;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Log
@Order(9)
public class UserRegisterAspect {
    @Autowired
    private JmsMessageProducter jmsMessageProductr;

    @Pointcut("execution(* com.zj.service.UserServiceImpl.sendVerifyCode(..))")
    public void VerifyCodePointcut() {
    }

    //通知的类型 before after afterReturning afterThrowing around
    //注册之前
    @AfterReturning(value = "VerifyCodePointcut()",returning = "obj")
    public void sendVerifyCodeEmailMessageToMQ(JoinPoint jp, Object obj){ //jp是连接点，即原注册方法 ，通过Jp可以获取到注册方法的参数，返回值，异常信息
        log.info("验证码生成成功，发送一条要发送给邮件信息到MQ");
        if (obj==null || !(obj instanceof MyUserDTO)){
            return;
        }
        MyUserDTO myUserDTO = (MyUserDTO) obj;
        log.info("生成的验证码是"+myUserDTO.getVerifyCode());
        jmsMessageProductr.sendVerifyCodeMessage(myUserDTO);

    }
}
